<?php

namespace App\Api\Models;

use DateTimeInterface;
use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Database\Eloquent\Model;

class LogPackageModel extends Model
{
    use HasFactory;

    protected $table = 'log_package';

    protected $dateFormat = 'U';//这个时间字段被为被格式化为UNIX 时间戳的形式存储
    //toArray 时间转换问题
    protected function serializeDate(DateTimeInterface $date)
    {
        return $date->format('Y-m-d H:i:s');
    }

    public function hasManyContent()
    {
        return SELF::hasMany(LogPackageContentModel::class, 'log_package_id', 'id');
    }

    //今日套餐总数
    static public function getTodayPackageCount($condition, $startTime, $endTime)
    {
        return SELF::where($condition)
            ->whereBetween('created_at', [$startTime, $endTime])
            ->count();
    }
}
